<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header(true)?>


    <?=$this->menu($this->parameter("menu"))?>


    <h1><?=$this->message("label.category.header", $this->parameter("bundle"))?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.category.header", $this->parameter("bundle")),
                "href"=>$this->parameter("module")."/category/list"
            ),
            array(
                "name"=>$this->languageRoute(
                            $this->message("label.category.item", $this->parameter("bundle")), // Item name
                            $this->categoryForm->getCategoryI18n()->getDefaultName(
                                $this->param(_Core::DEFAULT_LANGUAGE)),                        // Default language item name
                            $this->categoryForm->getCategoryI18n()->getCategoryI18nId(),       // Id
                            $this->categoryForm->getCategoryI18n()->getLanguage())             // Language
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->categoryForm)?>"
          action="<?=$this->parameter("module")?>/category/save"
          method="post"
          class="uniForm"
          enctype="multipart/form-data">

        <div>
            <input type="hidden"
                   name="categoryI18n->categoryId"
                   value="<?=$this->categoryForm->getCategoryI18n()->getCategoryId()?>" />
            <input type="hidden"
                   name="categoryI18n->categoryI18nId"
                   value="<?=$this->categoryForm->getCategoryI18n()->getCategoryI18nId()?>" />
            <input type="hidden"
                   name="categoryI18n->languageCode"
                   value="<?=$this->categoryForm->getCategoryI18n()->getLanguageCode()?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.required", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("categoryI18n->name")?>">
                <th><label for="categoryI18n_name"><?=$this->message("category.name", _Core::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="categoryI18n->name"
                           id="categoryI18n_name"
                           value="<?=$this->categoryForm->getCategoryI18n()->getName()?>"
                           maxlength="30"
                           type="text"
                           class="textInput" />
                </td>
            </tr>

            </table>

        </fieldset>

        <? /* Only show image with default language category */ ?>
        <? if($this->categoryForm->getCategoryI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>

        <fieldset>

            <legend><?=$this->message("label.optional", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">

            <? /*
            <tr class="ctrl<?=$this->error("categoryI18n->description")?>">
                <th><label for="categoryI18n_description"><?=$this->message("category.description", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <textarea id="categoryI18n_description" name="categoryI18n->description" rows="7" cols="80"><?=!is_null($this->categoryForm->getCategoryI18n()->getDescription()) ?
                        $this->categoryForm->getCategoryI18n()->getDescription()->getContents() : ""?></textarea>
                    <p class="hint"><?=$this->message("note.intro", _Core::BUNDLE)?></p>
                </td>
            </tr>

            <tr class="ctrl<?=$this->error("categoryI18n->body")?>">
                <th><label for="categoryI18n_body"><?=$this->message("prompt.body", _Core::BUNDLE)?></label></th>
                <th class="required"></th>
                <td>
                    <?
//                        ob_start();
//                        include($this->param(_Content::TEMPLATE));
//                        $tpl = htmlspecialchars(ob_get_contents());
//                        ob_end_clean();
                    ?>
                    <textarea id="categoryI18n_body" name="categoryI18n->body" mce_editable="true" rows="20" cols="80"><?=!is_null($this->categoryForm->getCategoryI18n()->getBody()) ?
                        htmlspecialchars($this->categoryForm->getCategoryI18n()->getBody()->getContents()) : ""?></textarea>
                    <p class="hint"><?=$this->message("note.body", _Core::BUNDLE, null, null, false)?></p>
                </td>
            </tr> */ ?>

            <tr class="ctrl<?=$this->error("formImage")?>">
                <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <? if(!is_null($this->categoryForm->getCategoryI18n()->getCategory()) &&
                        $this->categoryForm->getCategoryI18n()->getCategory()->getImageId() > 0 &&
                        !is_null($this->categoryForm->getCategoryI18n()->getCategory()->getImageRelatedByImageId())) { ?>

                        <input type="hidden"
                               name="categoryI18n->category->imageRelatedByImageId->imageId"
                               value="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageId()?>" />
                        <input type="hidden"
                               name="categoryI18n->category->imageRelatedByThumbnailId->imageId"
                               value="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getThumbnailId()?>" />

                        <input type="hidden"
                               name="categoryI18n->category->imageRelatedByImageId->binaryFileId"
                               value="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                        <input type="hidden"
                               name="categoryI18n->category->imageRelatedByThumbnailId->binaryFileId"
                               value="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                        <img src="image?id=<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageId()?>"
                             width="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageRelatedByImageId()->getWidth()?>"
                             height="<?=$this->categoryForm->getCategoryI18n()->getCategory()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                        <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>
                        <br /><br />

                    <? } ?>
                    <input type="file" name="formImage" />
                    <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_CATEGORY))->getImageWidth()?>x<?=$this->imageProps($this->param(_Core::SETTING_CATEGORY))->getImageHeight()?></p>
                </td>
            </tr>
            </table>

        </fieldset>

        <? endif ; ?>

        <div class="buttons">

            <input type="button"
                   onclick="to('<?=$this->parameter("module")?>/category/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   name="save"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>